<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成器例子2</title>
</head>
<body>
    <script>
        // 获取数据  用户数据 订单数据 商品数据
        function getUsers(){
            setTimeout(() => {
                let data = '用户数据';
                iteartor.next(data);
            },1000);
        }
        function getOrders(){
            setTimeout(() => {
                let data = '订单数据';
                iteartor.next(data);
            },1000);
        }
        function getGoods(){
            setTimeout(() => {
                let data = '商品数据';
                iteartor.next(data);
            },1000);
        }
        function *gen(){
            let users = yield getUsers();
            console.log(users);
            let orders = yield getOrders();
            console.log(orders);
            let goods = yield getGoods();
            console.log(goods);
        }
        let iteartor = gen();
        iteartor.next();
        /*
        这样子不符合真实场景
        getUsers();
        getOrders();
        getGoods()
        */
    </script>
</body>
</html>